package org.exam.blog.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.exam.blog.domain.Log;
import org.exam.blog.service.ILogService;
import org.exam.system.query.LogQuery;
import org.exam.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/log")
@Api(tags = "用户提示")
public class LogController {
    @ApiOperation(value = "查询单个接口")
    @PutMapping
    public JsonResult add(@RequestBody Log log) {
        try {
            if (log.getId() == null) {
                iLogService.add(log);
                return JsonResult.success();
            } else {
                iLogService.update(log);
                return JsonResult.success();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error();
        }
    }

    @Autowired
    private ILogService iLogService;

    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable Long id) {
        try {
            iLogService.delete(id);
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error();
        }
    }

    @GetMapping("/{id}")
    public Log get(Long id) {
        return iLogService.get(id);
    }

    @GetMapping
    public List<Log> getAll() {
        return iLogService.getAll();
    }

    @PatchMapping
    public JsonResult patchDelete(@RequestBody Long[] ids) {
        try {
            iLogService.patchDelete(ids);
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error();
        }
    }

    @PostMapping
    public PageInfo<Log> queryPage(@RequestBody LogQuery logQuery) {
        return iLogService.queryPage(logQuery);
    }




}
